// .vuepress/config.js
const fs = require('fs')
const path = require('path')

// 动态读取文档目录生成路由
function getDynamicRoutes() {
  const docsDir = path.join(__dirname, '../docs')
  const files = fs.readdirSync(docsDir)
  
  return files
    .filter(file => file.endsWith('.md') && file !== 'README.md')
    .map(file => ({
      path: `/${file.replace('.md', '')}`,
      file: `/${file}`
    }))
}

module.exports = {
  // 基础路由配置
  themeConfig: {
    // ...其他配置
  },
  // 动态生成路由
  async onInitialized(app) {
    const dynamicRoutes = getDynamicRoutes()
    dynamicRoutes.forEach(route => {
      app.pages.push({
        path: route.path,
        file: route.file,
        frontmatter: {}
      })
    })
  }
}
    